/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itschapala.com.dsw2.vista;

import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import mx.itschapala.com.dsw2.Bl.InventarioAlmacenBlLocal;
import mx.itschapala.com.dsw2.modelo.InventarioAlmacen;

/**
 *
 * @author z
 */
@ManagedBean
@SessionScoped
public class InventarioAlmacenBean {

    @EJB
    private InventarioAlmacenBlLocal inventarioAlmacenBl;

  //------------variables---------------- 
   private List<InventarioAlmacen> lista;
  private InventarioAlmacen inventa;
  private String accion;
  
     public InventarioAlmacenBean() {
          inventa = new  InventarioAlmacen();
    }

    public List<InventarioAlmacen> getLista() {
        return lista;
    }

//    public void setLista(List<InventarioAlmacen> lista) {
//        this.lista = lista;
//    }

    public InventarioAlmacen getInventa() {
        return inventa;
    }

    public void setInventa(InventarioAlmacen inventa) {
        this.inventa = inventa;
    }

    
    
    //-------------acciones-----------------

    
    public String relizarAccion(){
    if(accion.equalsIgnoreCase("nuevo")){
    inventarioAlmacenBl.register(inventa);
    }else{
    if(accion.equalsIgnoreCase("Editar")){
    inventarioAlmacenBl.modify(inventa);
    }else{
    if(accion.equalsIgnoreCase("Eliminar")){
  inventarioAlmacenBl.delete(inventa);
        }
    }
    }
    accion="";
    return "AdministradorLista";

}    
 
//-------------listeners----------------
    
    
public void preparaNuevo(ActionEvent e){
    inventa=new InventarioAlmacen(); 
    accion="Nuevo";
}
public void preparaEditar(ActionEvent evt){
       System.out.println(evt.getComponent().getClientId());
       int index = Integer.parseInt(evt.getComponent().getClientId().split(":")[2]);
       System.out.println("el numero es:"+ index);
     inventa=lista.get(index);
       accion="Editar";               
}
public void preparaEliminar(ActionEvent ev){
    int index = Integer.parseInt(ev.getComponent().getClientId().split(":")[2]);      
      inventa=lista.get(index);
accion="Eliminar";
}
   
}

 

 
    
    
    





